package com.woniuxy.buyer.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.woniuxy.buyer.entity.PointTransaction;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 积分流水Mapper
 */
@Mapper
public interface PointTransactionMapper extends BaseMapper<PointTransaction> {

    /**
     * 查询用户的积分流水
     */
    @Select("SELECT pt.*, u.nickname as username, op.nickname as operator_name " +
            "FROM point_transactions pt " +
            "LEFT JOIN users u ON pt.user_id = u.id " +
            "LEFT JOIN users op ON pt.operator_id = op.id " +
            "WHERE pt.user_id = #{userId} " +
            "ORDER BY pt.create_time DESC")
    List<PointTransaction> selectTransactionsByUserId(Long userId);
}
